package ne.aishuyuan.video.utils;
import cn.hutool.json.JSONUtil;
import com.google.protobuf.ByteString;
import ne.aishuyuan.video.bean.Packet;

import java.io.UnsupportedEncodingException;

/**
 * @author clj
 * @date 2021/11/15
 * @since 2021.1.0
 */
public class MessageUtil {
    public static Packet.Message buildMessage(Object object) throws UnsupportedEncodingException {
        ByteString text = ByteString.copyFrom(JSONUtil.toJsonStr(object),"UTF-8");
        Packet.Message packet = Packet.Message.newBuilder()
                .setMagic(1)
//              .setId(IdUtil.getWorkerId(0, 0))
                .setVersion(1)
                .setEa(Packet.EA.EA_UNSPECIFIED)
                .setSa(Packet.SA.SA_UNSPECIFIED)
                .setVa(Packet.VA.VA_UNSPECIFIED)
                .setType(Packet.Type.TYPE_CMD)
                .setCommand(0x00000000)
                .setLength(0)
                .setData(text)
                .build();
        return packet;
    }

}
